﻿Strict

Graphics 640,480,0,0
SeedRnd MilliSecs()

'#Region Includes
Include "Const.bmx"
Include "types\TCamera.bmx"
Include "types\TActor.bmx"
Include "types\TMob.bmx"
Include "types\TMap.bmx"
Include "types\TPlayer.bmx"
Include "types\TConsole.bmx"
Include "types\TTile.bmx"
'#End Region


'#Region Globals setup
SetImageFont mainFont
Global testMap:TMap = TMap.Create(60, 40)
Global console:TConsole = TConsole.Create()
Global player:TPlayer = TPlayer.Create(64, 3, 3)
Global camera:TCamera = TCamera.Create()
Global tstMob:TMob = TMob.Create(Asc("d"), 25, 17)
'#End Region


Local actor:TActor
While Not KeyHit(KEY_ESCAPE) Or AppTerminate()
	Cls()
	'#Region Cutting screen in half
	 'Upper part of the screen
	DrawLine(0, UpperBar, GW, UpperBar)
	 'Lower part of the screen
	DrawLine(0, GH - LowerBar, GW, GH - LowerBar)
'#End Region
	testMap.Draw()
	MovesControl()
	For actor = EachIn actorList
		actor.Draw()
		actor.Update()
	Next
	console.Draw()
	Flip()
Wend
End

'#Region Functions
'summary: Контролирует соблюдение ходов
Function MovesControl()
	Select turn
		Case 0
			If playerControls() Then turn = 1
		Case 1
		Local Actor:TActor
		For actor = EachIn actorList
			actor.Update()
		Next
		turn = 0
	End Select
End Function

'summary: Простое движение игрока
Function playerControls()
	Local res:Int
	If KeyHit(KEY_LEFT) Or KeyHit(KEY_NUM4) Then res = player.Move(-1, 0)
	If KeyHit(KEY_UP) Or KeyHit(KEY_NUM8) Then res = player.Move(0, -1)
	If KeyHit(KEY_DOWN) Or KeyHit(KEY_NUM2) Then res = player.Move(0, 1)
	If KeyHit(KEY_RIGHT) Or KeyHit(KEY_NUM6) Then res = player.Move(1, 0)
	
	If KeyHit(KEY_NUM1) Then res = player.Move(-1, 1)
	If KeyHit(KEY_NUM3) Then res = player.Move(1, 1)
	If KeyHit(KEY_NUM7) Then res = player.Move(-1, -1)
	If KeyHit(KEY_NUM9) Then res = player.Move(1, -1)
	Return res
End Function

'summary: Returns True if num is between limlow and limhigh
Function between(num:Int, limlow:Int, limhigh:Int)
	If num > limlow And num < limhigh Then Return True
	Return False
End Function

'summary: Returns string width(in px)
Function StringWidth(str:String, size:Int)
	Return size * Len(str)
End Function

'summary: Throws dice
Function dice(dicenmb, poly)
	Return Rnd(dicenmb, dicenmb * poly)
End Function

Function consoleAdd(txt:String)
	console.consoleAdd(txt)
End Function
'#End Region